VERSION 5.00
Begin VB.UserControl Label 
   AutoRedraw      =   -1  'True
   ClientHeight    =   1095
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   1095
   PropertyPages   =   "Label.ctx":0000
   ScaleHeight     =   1095
   ScaleWidth      =   1095
   ToolboxBitmap   =   "Label.ctx":0035
   Begin VB.Image IconIm 
      Height          =   615
      Left            =   240
      Top             =   240
      Visible         =   0   'False
      Width           =   615
   End
End
Attribute VB_Name = "Label"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

'Default value
Const m_def_CaptionShadowed = True
Const m_def_CaptionAligmend = 0
Const m_def_CaptionGradientType = 0
Const m_def_CaptionGradientChangeColor = False
Const m_def_CaptionGradientStart = &HFFFFFF
Const m_def_CaptionGradientEnds = &H404040
Const m_def_Transparent = True
Const m_def_DisplayType = 0
Const m_def_DisplayVertikal = False
Const m_def_CaptionOutlined = True
Const m_def_CaptionINColor = vbWhite
Const m_def_CaptionOUTColor = vbBlack
Const m_def_CaptionTransparent = False
Const m_def_AutoSize = False

'Private variables
Dim m_CaptionShadowed            As Boolean
Dim m_CaptionAligmend            As CaptionAlig
Dim m_CaptionGradientType        As TypGrad
Dim m_CaptionGradientChangeColor As Boolean
Dim m_CaptionGradientStart       As OLE_COLOR
Dim m_CaptionGradientEnds        As OLE_COLOR
Dim m_Transparent                As Boolean
Dim m_DisplayType                As DispTyp
Dim m_DisplayVertikal            As Boolean
Dim m_CaptionOutlined            As Boolean
Dim m_CaptionINColor             As OLE_COLOR
Dim m_CaptionOUTColor            As OLE_COLOR
Dim m_CaptionTransparent         As Boolean
Dim m_AutoSize                   As Boolean
Dim m_Caption                    As String

'Protected enum
Public Enum DispTyp
    [Left To Right]
    [Right To Left]
    [Top To Bottom]
    [Bottom To Top]
End Enum

Public Enum CaptionAlig
    [aLeft]
    [aCenter]
    [aRight]
End Enum

Public Enum TypGrad
    [None]
    [Horizontal]
    [Vertical]
End Enum

Public Enum InBord
    [Flat]
    [Inside]
    [Reized]
    [More Reized]
    [Extern Reized]
    [Out]
    [More Out]
    [Extern Out]
End Enum

Dim BorderPlusL
Dim BorderPlusT
Dim BorderPlusW
Dim BorderPlusH
Dim CurX, CurY, CurW, CurH

Const m_def_Borders = 0

Dim m_Borders   As InBord
Dim CaptionWork As Boolean

Dim OutLine     As Integer
Dim DspW, DspH
Private ConLinkKeys As String

'Event Declarations:
Event Click()
Event DblClick()
Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

' *********************************************************************************
' PROPERTIES
' *********************************************************************************

Public Property Get AutoSize() As Boolean
    AutoSize = m_AutoSize
End Property

Public Property Let AutoSize(ByVal New_AutoSize As Boolean)
    m_AutoSize = New_AutoSize
    PropertyChanged "AutoSize"
    Call LookAutoSize
    Call DrawText
End Property

Public Property Get BackColor() As OLE_COLOR
    BackColor = UserControl.BackColor
End Property

Public Property Let BackColor(ByVal New_BackColor As OLE_COLOR)
    UserControl.BackColor() = New_BackColor
    PropertyChanged "BackColor"
    Call DrawText
End Property

Public Property Get Borders() As InBord
    Borders = m_Borders
End Property

Public Property Let Borders(ByVal New_Borders As InBord)
    m_Borders = New_Borders
    PropertyChanged "Borders"
    Call BorderControlCap
    Call LookAutoSize
    Call DrawText
    UserControl_Resize
End Property

Public Property Get Caption() As String
    Caption = m_Caption
End Property

Public Property Let Caption(ByVal New_Caption As String)
    m_Caption = New_Caption
    PropertyChanged "Caption"
    Call LookAutoSize
    Call DrawText
End Property

Public Property Get CaptionAligmend() As CaptionAlig
    CaptionAligmend = m_CaptionAligmend
End Property

Public Property Let CaptionAligmend(ByVal New_CaptionAligmend As CaptionAlig)
    m_CaptionAligmend = New_CaptionAligmend
    PropertyChanged "CaptionAligmend"
    Call DrawText
End Property

Public Property Get CaptionGradientChangeColor() As Boolean
    CaptionGradientChangeColor = m_CaptionGradientChangeColor
End Property

Public Property Let CaptionGradientChangeColor(ByVal New_CaptionGradientChangeColor As Boolean)
    m_CaptionGradientChangeColor = New_CaptionGradientChangeColor
    PropertyChanged "CaptionGradientChangeColor"
    Call DrawText
End Property

Public Property Get CaptionGradientType() As TypGrad
    CaptionGradientType = m_CaptionGradientType
End Property

Public Property Let CaptionGradientType(ByVal New_CaptionGradientType As TypGrad)
    m_CaptionGradientType = New_CaptionGradientType
    PropertyChanged "CaptionGradientType"
    Call DrawText
End Property

Public Property Get CaptionGradientStart() As OLE_COLOR
    CaptionGradientStart = m_CaptionGradientStart
End Property

Public Property Let CaptionGradientStart(ByVal New_CaptionGradientStart As OLE_COLOR)
    m_CaptionGradientStart = New_CaptionGradientStart
    PropertyChanged "CaptionGradientStart"
    Call DrawText
End Property

Public Property Get CaptionGradientEnds() As OLE_COLOR
    CaptionGradientEnds = m_CaptionGradientEnds
End Property

Public Property Let CaptionGradientEnds(ByVal New_CaptionGradientEnds As OLE_COLOR)
    m_CaptionGradientEnds = New_CaptionGradientEnds
    PropertyChanged "CaptionGradientEnds"
    Call DrawText
End Property

Public Property Get CaptionINColor() As OLE_COLOR
    CaptionINColor = m_CaptionINColor
End Property

Public Property Let CaptionINColor(ByVal New_CaptionINColor As OLE_COLOR)
    m_CaptionINColor = New_CaptionINColor
    PropertyChanged "CaptionINColor"
    UserControl.ForeColor = m_CaptionINColor
    Call DrawText
End Property

Public Property Get CaptionOUTColor() As OLE_COLOR
    CaptionOUTColor = m_CaptionOUTColor
End Property

Public Property Let CaptionOUTColor(ByVal New_CaptionOUTColor As OLE_COLOR)
    m_CaptionOUTColor = New_CaptionOUTColor
    PropertyChanged "CaptionOUTColor"
    Call DrawText
End Property

Public Property Get CaptionOutlined() As Boolean
    CaptionOutlined = m_CaptionOutlined
End Property

Public Property Let CaptionOutlined(ByVal New_CaptionOutlined As Boolean)
    m_CaptionOutlined = New_CaptionOutlined
    PropertyChanged "CaptionOutlined"
    OutLine = 0

    If m_CaptionOutlined = True Then OutLine = 30: Call LookAutoSize
    Call DrawText
End Property

Public Property Get CaptionPicture() As StdPicture
    Set CaptionPicture = IconIm.Picture
End Property

Public Property Set CaptionPicture(ByVal New_CaptionPicture As StdPicture)
    Set IconIm.Picture = New_CaptionPicture
    PropertyChanged "CaptionPicture"
    Call LookAutoSize
    Call DrawText
End Property

Public Property Get CaptionShadowed() As Boolean
    CaptionShadowed = m_CaptionShadowed
End Property

Public Property Let CaptionShadowed(ByVal New_CaptionShadowed As Boolean)
    m_CaptionShadowed = New_CaptionShadowed
    PropertyChanged "CaptionShadowed"
    Call DrawText
End Property

Public Property Get CaptionTransparent() As Boolean
    CaptionTransparent = m_CaptionTransparent
End Property

Public Property Let CaptionTransparent(ByVal New_CaptionTransparent As Boolean)
    m_CaptionTransparent = New_CaptionTransparent
    PropertyChanged "CaptionTransparent"
    Call DrawText
End Property

Public Property Get ConLinkKey() As String
    ConLinkKey = ConLinkKeys
End Property

Public Property Let ConLinkKey(NewValue As String)
    ConLinkKeys = NewValue
End Property

Public Property Get DisplayType() As DispTyp
    DisplayType = m_DisplayType
End Property

Public Property Let DisplayType(ByVal New_DisplayType As DispTyp)
    m_DisplayType = New_DisplayType
    PropertyChanged "DisplayType"
    
    If m_DisplayVertikal = True Then
        If m_DisplayType = [Left To Right] Or m_DisplayType = [Right To Left] Then
            DisplayVertikal = False
            DspH = 0
            DspW = 0
        End If
    End If

    If m_DisplayVertikal = False Then
        If m_DisplayType = [Bottom To Top] Or m_DisplayType = [Top To Bottom] Then
        
            DisplayVertikal = True
            DspH = 0
            DspW = 0
        End If
    End If
    
    Call LookAutoSize
    Call DrawText
End Property

Public Property Get DisplayVertikal() As Boolean
    DisplayVertikal = m_DisplayVertikal
End Property

Public Property Let DisplayVertikal(ByVal New_DisplayVertikal As Boolean)
    m_DisplayVertikal = New_DisplayVertikal
    PropertyChanged "DisplayVertikal"
    DspH = 0
    DspW = 0

    If m_DisplayVertikal = True Then
        If m_DisplayType = [Left To Right] Or m_DisplayType = [Right To Left] Then
            If m_DisplayType = [Left To Right] Then
                DisplayType = [Top To Bottom]
            Else
                DisplayType = [Bottom To Top]
            End If
        End If
    Else

        If m_DisplayType = [Bottom To Top] Or m_DisplayType = [Top To Bottom] Then
            If m_DisplayType = [Top To Bottom] Then
                DisplayType = [Left To Right]
            Else
                DisplayType = [Right To Left]
            End If
        End If
    End If
    
    Call LookAutoSize
    Call DrawText
End Property

Public Property Get Enabled() As Boolean
    Enabled = UserControl.Enabled
End Property

Public Property Let Enabled(ByVal New_Enabled As Boolean)
    UserControl.Enabled() = New_Enabled
    PropertyChanged "Enabled"
    Call DrawText
End Property

Public Property Get Font() As Font
    Set Font = UserControl.Font
End Property

Public Property Set Font(ByVal New_Font As Font)
    Set UserControl.Font = New_Font
    PropertyChanged "Font"
    Call LookAutoSize
    Call DrawText
End Property

Public Property Get MouseIcon() As StdPicture
    Set MouseIcon = UserControl.MouseIcon
End Property

Public Property Set MouseIcon(ByVal New_MouseIcon As StdPicture)
    Set UserControl.MouseIcon = New_MouseIcon
    PropertyChanged "MouseIcon"
    Set IconIm.MouseIcon = UserControl.MouseIcon
End Property

Public Property Get MousePointer() As MousePointerConstants
    MousePointer = UserControl.MousePointer
End Property

Public Property Let MousePointer(ByVal New_MousePointer As MousePointerConstants)

    If New_MousePointer < vbDefault Then New_MousePointer = vbDefault
    If (New_MousePointer > vbSizeAll) And (New_MousePointer <> vbCustom) Then New_MousePointer = vbSizeAll
    UserControl.MousePointer() = New_MousePointer
    PropertyChanged "MousePointer"
    IconIm.MousePointer = UserControl.MousePointer
End Property

Public Property Get TRANSPARENT() As Boolean
    TRANSPARENT = m_Transparent
End Property

Public Property Let TRANSPARENT(ByVal New_Transparent As Boolean)
    m_Transparent = New_Transparent
    PropertyChanged "Transparent"
    UserControl_Resize
End Property

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    OutLine = 0
    IconIm.Width = 0
    IconIm.Stretch = False
    m_Caption = PropBag.ReadProperty("Caption", Ambient.DisplayName)
    m_Borders = PropBag.ReadProperty("Borders", m_def_Borders)
    m_Transparent = PropBag.ReadProperty("Transparent", m_def_Transparent)
    m_AutoSize = PropBag.ReadProperty("AutoSize", m_def_AutoSize)
    Set UserControl.Font = PropBag.ReadProperty("Font", Ambient.Font)
    UserControl.BackColor = PropBag.ReadProperty("BackColor", &H8000000F)
    m_CaptionINColor = PropBag.ReadProperty("CaptionINColor", m_def_CaptionINColor)
    m_CaptionOUTColor = PropBag.ReadProperty("CaptionOUTColor", m_def_CaptionOUTColor)
    m_CaptionTransparent = PropBag.ReadProperty("CaptionTransparent", m_def_CaptionTransparent)
    m_CaptionOutlined = PropBag.ReadProperty("CaptionOutlined", m_def_CaptionOutlined)
    m_DisplayVertikal = PropBag.ReadProperty("DisplayVertikal", m_def_DisplayVertikal)
    m_DisplayType = PropBag.ReadProperty("DisplayType", m_def_DisplayType)
    UserControl.ForeColor = m_CaptionINColor

    If m_CaptionOutlined = True Then OutLine = 30
    Set MouseIcon = PropBag.ReadProperty("MouseIcon", Nothing)
    UserControl.MousePointer = PropBag.ReadProperty("MousePointer", vbDefault)
    m_CaptionGradientStart = PropBag.ReadProperty("CaptionGradientStart", m_def_CaptionGradientStart)
    m_CaptionGradientEnds = PropBag.ReadProperty("CaptionGradientEnds", m_def_CaptionGradientEnds)
    m_CaptionGradientChangeColor = PropBag.ReadProperty("CaptionGradientChangeColor", m_def_CaptionGradientChangeColor)
    m_CaptionGradientType = PropBag.ReadProperty("CaptionGradientType", m_def_CaptionGradientType)
    UserControl.Enabled = PropBag.ReadProperty("Enabled", True)
    m_CaptionAligmend = PropBag.ReadProperty("CaptionAligmend", m_def_CaptionAligmend)
    m_CaptionShadowed = PropBag.ReadProperty("CaptionShadowed", m_def_CaptionShadowed)
    Set IconIm.Picture = PropBag.ReadProperty("CaptionPicture", Nothing)
    Set IconIm.MouseIcon = UserControl.MouseIcon
    IconIm.MousePointer = UserControl.MousePointer
    Call LookAutoSize
    Call DrawText
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    Call PropBag.WriteProperty("Caption", m_Caption, Ambient.DisplayName)
    Call PropBag.WriteProperty("Borders", m_Borders, m_def_Borders)
    Call PropBag.WriteProperty("Transparent", m_Transparent, m_def_Transparent)
    Call PropBag.WriteProperty("AutoSize", m_AutoSize, m_def_AutoSize)
    Call PropBag.WriteProperty("Font", UserControl.Font, Ambient.Font)
    Call PropBag.WriteProperty("BackColor", UserControl.BackColor, &H8000000F)
    Call PropBag.WriteProperty("CaptionINColor", m_CaptionINColor, m_def_CaptionINColor)
    Call PropBag.WriteProperty("CaptionOUTColor", m_CaptionOUTColor, m_def_CaptionOUTColor)
    Call PropBag.WriteProperty("CaptionTransparent", m_CaptionTransparent, m_def_CaptionTransparent)
    Call PropBag.WriteProperty("CaptionOutlined", m_CaptionOutlined, m_def_CaptionOutlined)
    Call PropBag.WriteProperty("DisplayVertikal", m_DisplayVertikal, m_def_DisplayVertikal)
    Call PropBag.WriteProperty("DisplayType", m_DisplayType, m_def_DisplayType)
    Call PropBag.WriteProperty("MouseIcon", MouseIcon, Nothing)
    Call PropBag.WriteProperty("MousePointer", UserControl.MousePointer, vbDefault)
    Call PropBag.WriteProperty("CaptionGradientStart", m_CaptionGradientStart, m_def_CaptionGradientStart)
    Call PropBag.WriteProperty("CaptionGradientEnds", m_CaptionGradientEnds, m_def_CaptionGradientEnds)
    Call PropBag.WriteProperty("CaptionGradientChangeColor", m_CaptionGradientChangeColor, m_def_CaptionGradientChangeColor)
    Call PropBag.WriteProperty("CaptionGradientType", m_CaptionGradientType, m_def_CaptionGradientType)
    Call PropBag.WriteProperty("Enabled", UserControl.Enabled, True)
    Call PropBag.WriteProperty("CaptionAligmend", m_CaptionAligmend, m_def_CaptionAligmend)
    Call PropBag.WriteProperty("CaptionShadowed", m_CaptionShadowed, m_def_CaptionShadowed)
    Call PropBag.WriteProperty("CaptionPicture", IconIm.Picture, Nothing)
End Sub

' *********************************************************************************
' FUNCTION
' *********************************************************************************

Public Property Get hwnd() As Long
    hwnd = UserControl.hwnd
End Property

Public Sub Clean()
    IconIm.Picture = LoadPicture("")
    Call Refresh
End Sub

Public Function TextHeight(ByVal Str As String) As Single

    If m_CaptionOutlined = True Then
        TextHeight = UserControl.TextHeight(Str) + 30
    Else
        TextHeight = UserControl.TextHeight(Str)
    End If
End Function

Public Function TextWidth(ByVal Str As String) As Single

    If m_CaptionOutlined = True Then
        TextWidth = UserControl.TextWidth(Str) + 30
    Else
        TextWidth = UserControl.TextWidth(Str)
    End If
End Function

Public Sub Refresh()
    IconIm.Refresh
    Call DrawText
    UserControl.Refresh
End Sub

' *********************************************************************************
' USER CONTROL
' *********************************************************************************

Private Sub IconIm_Click()
    RaiseEvent Click
End Sub

Private Sub IconIm_DblClick()
    RaiseEvent DblClick
End Sub

Private Sub IconIm_MouseDown(Button As Integer, _
                             Shift As Integer, _
                             X As Single, _
                             Y As Single)
    RaiseEvent MouseDown(Button, Shift, X + IconIm.Left, Y + IconIm.Top)
End Sub

Private Sub IconIm_MouseMove(Button As Integer, _
                             Shift As Integer, _
                             X As Single, _
                             Y As Single)
    RaiseEvent MouseMove(Button, Shift, X + IconIm.Left, Y + IconIm.Top)
End Sub

Private Sub IconIm_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    RaiseEvent MouseUp(Button, Shift, X + IconIm.Left, Y + IconIm.Top)
End Sub

Private Sub UserControl_Click()
    RaiseEvent Click
End Sub

Private Sub UserControl_DblClick()
    RaiseEvent DblClick
End Sub

Private Sub UserControl_MouseDown(Button As Integer, _
                                  Shift As Integer, _
                                  X As Single, _
                                  Y As Single)
    RaiseEvent MouseDown(Button, Shift, X, Y)
End Sub

Private Sub UserControl_MouseMove(Button As Integer, _
                                  Shift As Integer, _
                                  X As Single, _
                                  Y As Single)
    RaiseEvent MouseMove(Button, Shift, X, Y)
End Sub

Private Sub UserControl_MouseUp(Button As Integer, _
                                Shift As Integer, _
                                X As Single, _
                                Y As Single)
    RaiseEvent MouseUp(Button, Shift, X, Y)
End Sub

Private Sub UserControl_Resize()
    On Error Resume Next

    If CaptionWork = True Then Exit Sub
    Call LookAutoSize
    Call DrawText
End Sub

Private Sub UserControl_Show()
    Call LookAutoSize
    Call DrawText
End Sub

Private Sub UserControl_InitProperties()
    m_Caption = Ambient.DisplayName
    m_AutoSize = m_def_AutoSize
    Set UserControl.Font = Ambient.Font
    m_CaptionINColor = m_def_CaptionINColor
    m_CaptionOUTColor = m_def_CaptionOUTColor
    m_CaptionTransparent = m_def_CaptionTransparent
    m_CaptionOutlined = m_def_CaptionOutlined
    m_DisplayVertikal = m_def_DisplayVertikal
    m_DisplayType = m_def_DisplayType
    m_Transparent = m_def_Transparent
    m_CaptionGradientStart = m_def_CaptionGradientStart
    m_CaptionGradientEnds = m_def_CaptionGradientEnds
    m_CaptionGradientChangeColor = m_def_CaptionGradientChangeColor
    m_CaptionGradientType = m_def_CaptionGradientType
    m_CaptionAligmend = m_def_CaptionAligmend
    m_CaptionShadowed = m_def_CaptionShadowed
    IconIm.Width = 0
End Sub

' *********************************************************************************
' CUSTOM ROUTINES
' *********************************************************************************

Private Sub LookForDispleyType()
    Dim SS
    
    DspH = 0
    DspW = 0

    If m_DisplayVertikal = True Then

        For SS = 1 To Len(m_Caption)
            DspH = DspH + UserControl.TextHeight(Mid(m_Caption, SS, 1)) '/ 1.4

            If DspW < UserControl.TextWidth(Mid(m_Caption, SS, 1)) Then DspW = UserControl.TextWidth(Mid(m_Caption, SS, 1))
        Next
    End If
End Sub

Private Sub LookAutoSize()
    Dim ImWi, ImHei, Aly, Alw
    
    Call LookForDispleyType

    If m_AutoSize = True Then
        CaptionWork = True

        If IconIm.Picture > 0 Then
            ImWi = IconIm.Width
            ImHei = IconIm.Height
            Alw = IconIm.Width - UserControl.TextWidth(m_Caption)
            Aly = IconIm.Height - UserControl.TextHeight(m_Caption)

            If m_CaptionShadowed = True Then
                Aly = Aly + 45
            End If
        End If

        If m_DisplayVertikal = True Then
            UserControl.Size (DspW + (BorderPlusL) + (BorderPlusW) + (OutLine * 2)) + Alw, (DspH + BorderPlusT) + (BorderPlusH) + OutLine + ImHei
        Else
            UserControl.Size (UserControl.TextWidth(m_Caption) + (BorderPlusL) + (BorderPlusW) + OutLine) + ImWi, (UserControl.TextHeight(m_Caption) + (BorderPlusT) + (BorderPlusH) + OutLine) + Aly
        End If
        CaptionWork = False
    End If
End Sub

Private Sub DrawText()
    Dim SS
    Dim PoLeft As Single, PoTop As Single, DD As Single
    
    UserControl.Cls

    If m_CaptionGradientType <> None Then DrawColor m_CaptionGradientChangeColor
    
    Dim Capp As String
    Capp = m_Caption
    Dim CuW, CuH
    
    PoLeft = BorderPlusL
    PoTop = BorderPlusT
    DD = (BorderPlusT) + OutLine

    Select Case m_DisplayType

        Case 0
            DrawProcent Capp, PoLeft, PoTop
            CuW = UserControl.TextWidth(Capp)
            CuH = UserControl.TextHeight(Capp)

        Case 1
            Dim ST As String
            
            For SS = 0 To Len(Capp) - 1
                ST = ST + Mid(Capp, Len(Capp) - SS, 1)
            Next
            DrawProcent ST, PoLeft, PoTop
            CuW = UserControl.TextWidth(ST)
            CuH = UserControl.TextHeight(ST)

        Case 2
            PoLeft = (UserControl.ScaleWidth / 2 - DspW / 2)

            For SS = 1 To Len(Capp)

                If CuW < UserControl.TextWidth(Mid(Capp, SS, 1)) Then CuW = UserControl.TextWidth(Mid(Capp, SS, 1))
                DrawProcent Mid(Capp, SS, 1), Fix(UserControl.ScaleWidth / 2 - UserControl.TextWidth(Mid(Capp, SS, 1)) / 2), DD '/ 1.41221
                DD = DD + UserControl.TextHeight(Mid(Capp, SS, 1)) '/ 1.4
                CuH = DD
            Next

        Case 3
            PoLeft = (UserControl.ScaleWidth / 2 - DspW / 2)

            For SS = 0 To Len(Capp) - 1

                If CuW < UserControl.TextWidth(Mid(Capp, Len(Capp) - SS, 1)) Then CuW = UserControl.TextWidth(Mid(Capp, Len(Capp) - SS, 1))
                DrawProcent Mid(Capp, Len(Capp) - SS, 1), Fix(UserControl.ScaleWidth / 2 - UserControl.TextWidth(Mid(Capp, Len(Capp) - SS, 1)) / 2), DD ' / 1.41221
                DD = DD + UserControl.TextHeight(Mid(Capp, Len(Capp) - SS, 1)) ' / 1.4
                CuH = DD
            Next
    End Select
    
    CurX = BorderPlusL
    CurY = BorderPlusT
    CurW = UserControl.ScaleWidth - BorderPlusL * 2
    CurH = UserControl.ScaleHeight - BorderPlusT * 2
End Sub

Private Sub DrawProcent(TextToPrint As String, DspX As Single, DspY As Single)
    Dim Captio, AliX, AliY
    Captio = TextToPrint
    Dim FORC As OLE_COLOR
    FORC = UserControl.ForeColor
    Dim PosLeft
    Dim PosTop
    Dim CapOutCol As OLE_COLOR
    Dim ImW
    
    If IconIm.Picture > 0 Then ImW = IconIm.Width
    Call BorderControlCap

    If m_DisplayVertikal = False Then

        Select Case m_CaptionAligmend

            Case 0

                If m_CaptionShadowed = True Then
                    AliX = 0
                    AliY = Fix(Fix(((UserControl.ScaleHeight - 30) / 2) - (UserControl.TextHeight(Captio) / 2))) - DspY
                Else
                    AliX = 0
                    AliY = Fix(Fix(UserControl.ScaleHeight / 2 - UserControl.TextHeight(Captio) / 2)) - DspY
                End If

            Case 1

                If m_CaptionShadowed = True Then
                    AliX = Fix(Fix(((UserControl.ScaleWidth - 45) / 2) - (UserControl.TextWidth(Captio) / 2))) - ImW / 2 - DspX
                    AliY = Fix(Fix(((UserControl.ScaleHeight - 30) / 2) - (UserControl.TextHeight(Captio) / 2))) - DspY
                Else
                    AliX = Fix(Fix((UserControl.ScaleWidth / 2) - (UserControl.TextWidth(Captio) / 2))) - ImW / 2 - DspX - 20
                    AliY = Fix(Fix((UserControl.ScaleHeight / 2) - (UserControl.TextHeight(Captio) / 2))) - DspY
                End If

            Case 2

                If m_CaptionShadowed = True Then
                    AliX = Fix(UserControl.ScaleWidth - UserControl.TextWidth(Captio)) - (DspX * 2) - ImW - 30
                    AliY = Fix(Fix(UserControl.ScaleHeight / 2 - UserControl.TextHeight(Captio) / 2)) - DspY - 20
                Else
                    AliX = Fix(UserControl.ScaleWidth - UserControl.TextWidth(Captio)) - (DspX * 2) - ImW - 30
                    AliY = Fix(Fix((UserControl.ScaleHeight / 2) - (UserControl.TextHeight(Captio) / 2))) - DspY
                End If
        End Select
    End If
    
    PosLeft = ImW + DspX + AliX
    PosTop = DspY + AliY
    
    CapOutCol = CaptionOUTColor

    If UserControl.Enabled = False Then
        CapOutCol = &H808080
    Else

        If m_CaptionShadowed = True Then
            UserControl.ForeColor = &H808080
            UserControl.CurrentX = PosLeft + 45
            UserControl.CurrentY = PosTop + 45
            UserControl.Print Captio
        End If
    End If
    
    If m_CaptionOutlined = True Then
        If m_DisplayVertikal = False Then
            PosLeft = ImW + AliX + DspX + 15
            PosTop = AliY + DspY + 15
        End If
        UserControl.ForeColor = CapOutCol
        UserControl.CurrentX = PosLeft - 15
        UserControl.CurrentY = PosTop - 15
        UserControl.Print Captio
        UserControl.CurrentX = PosLeft - 15
        UserControl.CurrentY = PosTop
        UserControl.Print Captio
        UserControl.CurrentX = PosLeft
        UserControl.CurrentY = PosTop - 15
        UserControl.Print Captio
        UserControl.CurrentX = PosLeft - 15
        UserControl.CurrentY = PosTop + 15
        UserControl.Print Captio
        UserControl.CurrentX = PosLeft + 15
        UserControl.CurrentY = PosTop - 15
        UserControl.Print Captio
        UserControl.CurrentX = PosLeft + 15
        UserControl.CurrentY = PosTop
        UserControl.Print Captio
        UserControl.CurrentX = PosLeft + 15
        UserControl.CurrentY = PosTop
        UserControl.Print Captio
        UserControl.CurrentX = PosLeft
        UserControl.CurrentY = PosTop + 15
        UserControl.Print Captio
        UserControl.CurrentX = PosLeft + 15
        UserControl.CurrentY = PosTop + 15
        UserControl.Print Captio
    End If
    
    If CaptionTransparent = True Then
        UserControl.ForeColor = UserControl.BackColor
    Else
        UserControl.ForeColor = CaptionINColor
    End If
    
    If UserControl.Enabled = False Then
        UserControl.ForeColor = &HE0E0E0
    End If
    
    UserControl.CurrentX = PosLeft
    UserControl.CurrentY = PosTop
    UserControl.Print Captio
    
    If IconIm.Picture > 0 Then
        UserControl.PaintPicture IconIm.Picture, 0 + BorderPlusL, ((UserControl.ScaleHeight / 2) - (IconIm.Height / 2)) + BorderPlusT, IconIm.Width, IconIm.Height
    End If
    
    If m_Transparent = True Then
        UserControl.MaskColor = UserControl.BackColor
        UserControl.MaskPicture = UserControl.Image
        UserControl.BackStyle = 0
    Else
        UserControl.BackStyle = 1
    End If
    
    UserControl.ForeColor = FORC
    Call BorderControlCap
End Sub

Private Sub DrawClear()
    Call BorderControlCap
    
    UserControl.CurrentX = UserControl.ScaleWidth / 2 - UserControl.TextWidth(Caption) / 2
    UserControl.CurrentY = UserControl.ScaleHeight / 2 - UserControl.TextHeight(Caption) / 2
    UserControl.Print Caption
    
    If m_Transparent = True Then
        UserControl.MaskColor = UserControl.ForeColor
        UserControl.MaskPicture = UserControl.Image
        UserControl.BackStyle = 0
    Else
        UserControl.BackStyle = 1
    End If
End Sub

Private Sub BorderControlCap()
    'Exit Sub
    Dim Scal
    Dim UCSw, UCSh
    Dim ShadowWi, ShadowHei

    'UserControl.Cls
    Scal = UserControl.ScaleMode
    ScaleMode = 1 'twip
    UCSw = UserControl.ScaleWidth - ShadowWi
    UCSh = UserControl.ScaleHeight - ShadowHei

    If m_Borders = [Flat] Then
        BorderPlusL = 0
        BorderPlusT = 0
        BorderPlusW = 0
        BorderPlusH = 0
        GoTo Exodos
    End If
    
    If m_Borders = [Inside] Then
        BorderPlusL = 30
        BorderPlusT = 30
        BorderPlusW = 30
        BorderPlusH = 30
        UserControl.Line (0, 0)-(UCSw, 0), vb3DShadow
        UserControl.Line (0, 15)-(UCSw, 15), vb3DDKShadow
        UserControl.Line (0, 0)-(0, UCSh), vb3DShadow
        UserControl.Line (15, 15)-(15, UCSh), vb3DDKShadow
        
        UserControl.Line (UCSw - 15, 0)-(UCSw - 15, UCSh), vb3DHighlight
        UserControl.Line (UCSw - 30, 15)-(UCSw - 30, UCSh), vb3DLight
        UserControl.Line (15, UCSh - 15)-(UCSw - 15, UCSh - 15), vb3DHighlight
        UserControl.Line (30, UCSh - 30)-(UCSw - 30, UCSh - 30), vb3DLight
        GoTo Exodos
    End If
    
    If m_Borders = [Reized] Then
        BorderPlusL = 30
        BorderPlusT = 30
        BorderPlusW = 30
        BorderPlusH = 30
        UserControl.Line (0, 0)-(UCSw - 15, 0), vb3DHighlight
        UserControl.Line (0, 15)-(UCSw - 15, 15), vb3DDKShadow
        UserControl.Line (0, 0)-(0, UCSh - 15), vb3DHighlight
        UserControl.Line (15, 15)-(15, UCSh - 15), vb3DDKShadow
        
        UserControl.Line (UCSw - 30, 0)-(UCSw - 30, UCSh - 15), vb3DHighlight
        UserControl.Line (UCSw - 15, 0)-(UCSw - 15, UCSh), vb3DDKShadow
        UserControl.Line (0, UCSh - 15)-(UCSw, UCSh - 15), vb3DDKShadow
        UserControl.Line (30, UCSh - 30)-(UCSw - 15, UCSh - 30), vb3DHighlight
        GoTo Exodos
    End If
    
    If m_Borders = [Out] Then
        BorderPlusL = 15
        BorderPlusT = 15
        BorderPlusW = 15
        BorderPlusH = 15
        UserControl.Line (0, 0)-(UCSw, 0), vb3DDKShadow
        UserControl.Line (0, 0)-(0, UCSh), vb3DDKShadow
        UserControl.Line (UCSw - 15, 0)-(UCSw - 15, UCSh), vb3DDKShadow
        UserControl.Line (15, UCSh - 15)-(UCSw - 15, UCSh - 15), vb3DDKShadow
        GoTo Exodos
    End If
    
    If m_Borders = [More Out] Then
        BorderPlusL = 45
        BorderPlusT = 45
        BorderPlusW = 45
        BorderPlusH = 45
        UserControl.Line (0, 0)-(UCSw, 0), vb3DDKShadow
        UserControl.Line (0, 15)-(UCSw, 15), vb3DShadow
        UserControl.Line (0, 30)-(UCSw, 30), vb3DLight
    
        UserControl.Line (0, 0)-(0, UCSh), vb3DDKShadow
        UserControl.Line (15, 15)-(15, UCSh), vb3DShadow
        UserControl.Line (30, 30)-(30, UCSh), vb3DLight
    
        UserControl.Line (UCSw - 15, 0)-(UCSw - 15, UCSh), vb3DDKShadow
        UserControl.Line (UCSw - 30, 15)-(UCSw - 30, UCSh), vb3DShadow
        UserControl.Line (UCSw - 45, 30)-(UCSw - 45, UCSh), vb3DLight
    
        UserControl.Line (15, UCSh - 15)-(UCSw - 15, UCSh - 15), vb3DDKShadow
        UserControl.Line (30, UCSh - 30)-(UCSw - 30, UCSh - 30), vb3DShadow
        UserControl.Line (45, UCSh - 45)-(UCSw - 45, UCSh - 45), vb3DLight
        GoTo Exodos
    End If
    
    If m_Borders = [More Reized] Then
        BorderPlusL = 45
        BorderPlusT = 45
        BorderPlusW = 45
        BorderPlusH = 45
        UserControl.Line (0, 0)-(UCSw, 0), vb3DHighlight
        UserControl.Line (0, 15)-(UCSw, 15), vb3DShadow
        UserControl.Line (0, 30)-(UCSw, 30), vb3DDKShadow
    
        UserControl.Line (0, 0)-(0, UCSh), vb3DHighlight
        UserControl.Line (15, 15)-(15, UCSh), vb3DShadow
        UserControl.Line (30, 30)-(30, UCSh - 45), vb3DDKShadow
    
        UserControl.Line (UCSw - 15, 0)-(UCSw - 15, UCSh), vb3DDKShadow
        UserControl.Line (UCSw - 30, 15)-(UCSw - 30, UCSh), vb3DShadow
        UserControl.Line (UCSw - 45, 30)-(UCSw - 45, UCSh), vb3DHighlight
    
        UserControl.Line (0, UCSh - 15)-(UCSw - 15, UCSh - 15), vb3DDKShadow
        UserControl.Line (30, UCSh - 30)-(UCSw - 30, UCSh - 30), vb3DShadow
        UserControl.Line (30, UCSh - 45)-(UCSw - 45, UCSh - 45), vb3DHighlight
        GoTo Exodos
    End If
    
    If m_Borders = [Extern Out] Then
        BorderPlusL = 60
        BorderPlusT = 60
        BorderPlusW = 60
        BorderPlusH = 60
        UserControl.Line (0, 0)-(UCSw, 0), vb3DDKShadow
        UserControl.Line (0, 15)-(UCSw, 15), vb3DShadow
        UserControl.Line (0, 30)-(UCSw, 30), vb3DLight
        UserControl.Line (0, 45)-(UCSw, 45), vb3DHighlight
    
        UserControl.Line (0, 0)-(0, UCSh), vb3DDKShadow
        UserControl.Line (15, 15)-(15, UCSh), vb3DShadow
        UserControl.Line (30, 30)-(30, UCSh), vb3DLight
        UserControl.Line (45, 45)-(45, UCSh), vb3DHighlight
    
        UserControl.Line (UCSw - 15, 0)-(UCSw - 15, UCSh), vb3DDKShadow
        UserControl.Line (UCSw - 30, 15)-(UCSw - 30, UCSh), vb3DShadow
        UserControl.Line (UCSw - 45, 30)-(UCSw - 45, UCSh), vb3DLight
        UserControl.Line (UCSw - 60, 45)-(UCSw - 60, UCSh), vb3DHighlight
    
        UserControl.Line (15, UCSh - 15)-(UCSw - 15, UCSh - 15), vb3DDKShadow
        UserControl.Line (30, UCSh - 30)-(UCSw - 30, UCSh - 30), vb3DShadow
        UserControl.Line (45, UCSh - 45)-(UCSw - 45, UCSh - 45), vb3DLight
        UserControl.Line (60, UCSh - 60)-(UCSw - 60, UCSh - 60), vb3DHighlight
    End If
    
    If m_Borders = [Extern Reized] Then
        BorderPlusL = 60
        BorderPlusT = 60
        BorderPlusW = 60
        BorderPlusH = 60
        UserControl.Line (0, 0)-(UCSw, 0), vb3DHighlight
        UserControl.Line (0, 15)-(UCSw, 15), vb3DLight
        UserControl.Line (0, 30)-(UCSw, 30), vb3DShadow
        UserControl.Line (0, 45)-(UCSw, 45), vb3DDKShadow
    
        UserControl.Line (0, 0)-(0, UCSh), vb3DHighlight
        UserControl.Line (15, 15)-(15, UCSh), vb3DLight
        UserControl.Line (30, 30)-(30, UCSh), vb3DShadow
        UserControl.Line (45, 45)-(45, UCSh), vb3DDKShadow
    
        UserControl.Line (UCSw - 15, 0)-(UCSw - 15, UCSh), vb3DDKShadow
        UserControl.Line (UCSw - 30, 15)-(UCSw - 30, UCSh), vb3DShadow
        UserControl.Line (UCSw - 45, 30)-(UCSw - 45, UCSh), vb3DLight
        UserControl.Line (UCSw - 60, 45)-(UCSw - 60, UCSh), vb3DHighlight
    
        UserControl.Line (0, UCSh - 15)-(UCSw - 15, UCSh - 15), vb3DDKShadow
        UserControl.Line (15, UCSh - 30)-(UCSw - 30, UCSh - 30), vb3DShadow
        UserControl.Line (30, UCSh - 45)-(UCSw - 45, UCSh - 45), vb3DLight
        UserControl.Line (45, UCSh - 60)-(UCSw - 60, UCSh - 60), vb3DHighlight
    End If
    
Exodos:
    ScaleMode = Scal
    'UserControl.Refresh
End Sub

Private Sub DrawColor(Colorchange As Boolean)
    Dim VR, VG, VB As Single
    Dim Color1 As OLE_COLOR, Color2 As OLE_COLOR
    Dim dR, dG, dB, DR2, DG2, DB2 As Integer
    Dim Temp As Long
    Dim X, Y As Integer

    CurW = UserControl.ScaleWidth - BorderPlusL * 2
    CurH = UserControl.ScaleHeight - BorderPlusT * 2

    If Colorchange = True Then
        Color2 = m_CaptionGradientStart
        Color1 = m_CaptionGradientEnds
    Else
        Color2 = m_CaptionGradientEnds
        Color1 = m_CaptionGradientStart
    End If

    Temp = (Color1 And 255)
    dR = Temp And 255
    Temp = Int(Color1 / 256)
    dG = Temp And 255
    Temp = Int(Color1 / 65536)
    dB = Temp And 255
    Temp = (Color2 And 255)
    DR2 = Temp And 255
    Temp = Int(Color2 / 256)
    DG2 = Temp And 255
    Temp = Int(Color2 / 65536)
    DB2 = Temp And 255

    If m_CaptionGradientType = Vertical Then
        VR = Abs(dR - DR2) / (CurY + CurH)
        VG = Abs(dG - DG2) / (CurY + CurH)
        VB = Abs(dB - DB2) / (CurY + CurH)

        If DR2 < dR Then VR = -VR
        If DG2 < dG Then VG = -VG
        If DB2 < dB Then VB = -VB

        For Y = 1 To CurH Step 15
            DR2 = dR + VR * Y
            DG2 = dG + VG * Y
            DB2 = dB + VB * Y
            UserControl.Line (CurX, CurY + Y)-(CurX + CurW, CurY + Y), RGB(DR2, DG2, DB2)
        Next Y

    Else
        VR = Abs(dR - DR2) / (CurX + CurW)
        VG = Abs(dG - DG2) / (CurX + CurW)
        VB = Abs(dB - DB2) / (CurX + CurW)

        If DR2 < dR Then VR = -VR
        If DG2 < dG Then VG = -VG
        If DB2 < dB Then VB = -VB

        For X = 1 To CurW Step 15
            DR2 = dR + VR * X
            DG2 = dG + VG * X
            DB2 = dB + VB * X
            UserControl.Line (CurX + X, CurY)-(CurX + X, CurY + CurH), RGB(DR2, DG2, DB2)
        Next X

    End If
End Sub
